package com.qianbao.qianbaobusiness.ui.help;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.androidbase.widget.recycleadpter.BaseRecycleViewAdapter;
import com.qianbao.qianbaobusiness.R;
import com.qianbao.qianbaobusiness.json.HelpListBean;
import com.qianbao.qianbaobusiness.ui.cashier.QuestionDetailActivity;
import com.qianbao.qianbaobusiness.ui.start.StartActivity;
import com.qianbao.qianbaobusiness.ui.widget.FlowLayout;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 帮助中心适配器
 */
public class HelpCenterAdapter extends BaseRecycleViewAdapter<HelpListBean> {

    public HelpCenterAdapter(Context context) {
        super(context);
    }

    @Override
    protected void onBindBaseViewHolder(RecyclerView.ViewHolder holder, HelpListBean item) {
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.tvHelplistTitle.setText(item.getTopicName());
        for (int i = 0 ;i < item.getHelpContentList().size(); i++){
            View view = LayoutInflater.from(mContext).inflate(R.layout.item_help_content,null);
            TextView tvContent = view.findViewById(R.id.tv_helplist_content);
            tvContent.setText(item.getHelpContentList().get(i).getTitle());
            int finalI = i;
            tvContent.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext,QuestionDetailActivity.class) ;
                    intent.putExtra("parenttitle", item.getTopicName());
                    intent.putExtra("title", item.getHelpContentList().get(finalI).getTitle());
                    intent.putExtra("content", item.getHelpContentList().get(finalI).getContent());
                    mContext.startActivity(intent);
                }
            });
            viewHolder.flowContent.addView(view);
        }
    }

    @Override
    protected RecyclerView.ViewHolder onCreateBaseViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_help_list,parent,false);
        return new ViewHolder(view);
    }

    @Override
    protected int getBaseItemViewType(int position) {
        return 0;
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.tv_helplist_title)
        TextView tvHelplistTitle ;
        @BindView(R.id.flow_content)
        FlowLayout flowContent ;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }

}
